<?php
/**
 * Created by PhpStorm.
 * User: tengwei
 * Date: 2018/11/16
 * Time: 10:17 AM
 */

namespace common\sources\read\bank;

use common\models\craftsman\BusinessAdvice;
use common\models\craftsman\BuyUser;
use common\models\craftsman\BuyUserBankAccount;

class BankAccess implements IBankAccess
{
    public function getBankList($data){
        return BuyUserBankAccount::find()
                ->select("id,real_name,cardnum,bankname,bankbranch,idcard,status")
                ->orderBy("create_time desc")
                ->asArray()
                ->all();
    }

    public function getBankMessage($bus_id)
    {
        return BuyUserBankAccount::find()
            ->select("id,real_name,cardnum,bankname,bankbranch,idcard,status,AliPay")
            ->where(['buy_id' => $bus_id])
            ->asArray()
            ->one();
    }

    public function UserBankList($data) {
        $query = BuyUserBankAccount::find()
            ->select("id,real_name,buy_id,AliPay,cardnum,idcard,bankphone,status,aliUrl,bankCardUrl,idCardUrl,operator,reason,refuse_plat,id_positive_url,id_verso_url");
        if (!empty($data['status'])) {
            $query = $query->andWhere(['status' => $data['status']]);
        }
        if (1 == $data['search_type'] && !empty($data['value'])) {//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
            $buy_id = BuyUser::find()->select('id')->where(['phone' => $data['value']])->asArray()->one();
            if ($buy_id) {
                $query = $query->andWhere(['buy_id' => $buy_id['id']]);
            }
        }
        if (2 == $data['search_type'] && !empty($data['value'])) {//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
            $query = $query->andWhere(['real_name' => $data['value']]);
        }
        if (3 == $data['search_type'] && !empty($data['value'])) {//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
            $query = $query->andWhere(['AliPay' => $data['value']]);
        }
        if (4 == $data['search_type'] && !empty($data['value'])) {//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
            $query = $query->andWhere(['Cftnum' => $data['value']]);
        }
        if (5 == $data['search_type'] && !empty($data['value'])) {//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
            $query = $query->andWhere(['cardnum' => $data['value']]);
        }
        if (6 == $data['search_type'] && !empty($data['value'])) {//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
            $query = $query->andWhere(['idcard' => $data['value']]);
        }
        $list = $query->asArray()
            ->all();
        return $list;
    }

    public function AuditDataRefus($data) {
        $query = BuyUserBankAccount::find()
            ->where(['status' => 3])
            ->andWhere(['audit_operator' => $data['worker']]);
        if (!empty($data['begin_time'])) {
            $query->andWhere([
                '>',
                'audit_time',
                $data['begin_time']
            ]);
        }
        if (!empty($data['end_time'])) {
            $query->andWhere([
                '>',
                'audit_time',
                $data['begin_time']
            ]);
        }
        $num = $query->count();
        return $num;
    }

    public function AuditDataPass($data) {
        $query = BuyUserBankAccount::find()
            ->where(['status' => 2])
            ->andWhere(['audit_operator' => $data['worker']]);
        if (!empty($data['begin_time'])) {
            $query->andWhere([
                '>',
                'audit_time',
                $data['begin_time']
            ]);
        }
        if (!empty($data['end_time'])) {
            $query->andWhere([
                '>',
                'audit_time',
                $data['begin_time']
            ]);
        }
        $num = $query->count();
        return $num;
    }
    //买手提现信息审核
    public function getBankAduitCount($data)
    {
        return BuyUserBankAccount::find()
                ->where($data)
                ->count();
    }
}